package com.dyna.web;

import com.dyna.bean.AdminUsernameAndPasswordBean;
import com.dyna.service.AdminLoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.annotation.Resource;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@Controller
public class AdminLoginController {

    @Autowired
    private AdminLoginService adminLoginService;
    //这个是来到Admin后台登录页面
    @RequestMapping(value = "/Admin")
    public String Admin(){
        return "AdminLogin";
    }
    @RequestMapping(value = "/AdminManagerPage")
    public String AdminManagerPage(@RequestParam String username, @RequestParam String password, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("UTF-8");
        response.setContentType("text/html;charset=UTF-8");
        if (username!=null){
            if (password!=null){
                AdminUsernameAndPasswordBean adminLogin = adminLoginService.findAdminLogin(username, password);
                if (adminLogin!=null){
                    System.out.println(adminLogin);
                }else {
                    System.out.println(adminLogin);
                    request.setAttribute("info","登录失败");
                    request.getRequestDispatcher("/Admin").forward(request,response);

                }
            } else {
                request.setAttribute("info","请重新输入密码");
                request.getRequestDispatcher("/Admin").forward(request,response);
            }
        }else {
            request.setAttribute("info","请输入用户名");
            request.getRequestDispatcher("/Admin").forward(request,response);
        }
        return "UserManagement";
    }
    @RequestMapping(value = "/search")
    public String search(@RequestParam String InTelePhone){
        System.out.println(InTelePhone);
        return "UserManagement";
    }

}
